<?php

namespace app\index\controller;

use app\api\model\xykeep\course\OrderSeat as CourseOrderSeatModel;
use app\api\model\xykeep\User;
use app\common\controller\Frontend;
use think\Config;
use app\api\model\xykeep\course\Order as OrderModel;
use think\Db;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        return $this->view->fetch();
    }

    public function fontsize()
    {
//        $course_list = Db::name('xykeep_course')->order('id desc')->select();
//        foreach ($course_list as $k => $v) {
//            $intro = $v['intro'];
//            if (strpos($intro, "14px") !== false) {
//                $r_intro = str_replace("14px", "13px", $intro);
//                Db::name('xykeep_course')->where('id', $v['id'])->update(['intro' => $r_intro]);
//            }
//            $rule = $v['rule'];
//            if (strpos($rule, "14px") !== false) {
//                $r_rule = str_replace("14px", "13px", $rule);
//                Db::name('xykeep_course')->where('id', $v['id'])->update(['rule' => $r_rule]);
//            }
//            $note = $v['note'];
//            if (strpos($note, "14px") !== false) {
//                $r_note = str_replace("14px", "13px", $note);
//                Db::name('xykeep_course')->where('id', $v['id'])->update(['note' => $r_note]);
//            }
//
//        }
    }

//    public function repeat_order()
//    {
//        $orderModel = new \app\admin\model\xykeep\course\Order();
//        $where = [];
//        $where['createtime'] = ['between',[1727611200,1727625600]];
//        $where['status'] = ['in',[1,2,3]];
//        $where['service_start_time'] = ['gt', 1727625600];
//        $repeat_user = [];
//        $repeat_user1 = [];
//        $res = Db::name('xykeep_course_order')->field('id,order_sn,user_id')->where($where)->select();
//        foreach ($res as $key => $value) {
//            if(in_array($value['user_id'],$repeat_user)){
////                $row = $orderModel->where(['id'=>$value['id']])->find();
////                $result = $orderModel->allowField(true)->save(['status'=>-3,'refundtime'=>time()]);
////                $params['order'] = $row;
////                $params['type'] = 'course';
////                \think\Hook::listen('xykeep_order_refund_after', $params);
//
//
//                echo $value['user_id'].':'.$value['order_sn'];
//                echo '<br>';
//                $repeat_user1[] = $value['user_id'];
//            }else{
//                $repeat_user[] = $value['user_id'];
//            }
//        }
//        print_r($repeat_user1);
////        echo $res;
//    }

    public function delete_third()
    {
//        $third_list = Db::name('xykeep_third')->order('id desc')->select();
//        foreach ($third_list as $k => $v) {
//            $user = Db::name('user')->where('id', $v['user_id'])->find();
//            if(!$user){
//                echo $v['user_id'].',';
//            }
//        }
    }

//    public function push_wxmsg()
//    {
//        $orderModel = new OrderModel();
//        $order = $orderModel->where(['id'=>691])->find();
//        $unionId = getUnionId($order['user_id']);
//
//        $user_info = User::where(['id'=>$order['user_id']])->find();
//
//        $service_duration = date('m-d H:i',$order['service_start_time']).'~'.date('H:i',$order['service_end_time']);
//
//        $message = array(
//            'thing16' => $user_info['nickname'],
//            'phone_number3' => $user_info['mobile'],
//            'amount5' => $order['total_fee'],
//            'thing4' => $order['name'],
//            'time18' => $service_duration
//        );
//
//        //给用户自己发送通知
//        $unionId = getUnionId($order['user_id']);
//        if($unionId){
//            $res = \addons\weixin\library\WechatTemplateService::sendTemplate(
//                $unionId,//用户openid
//                'course_order_create',//自定义模板编号
//                $message,
//                '/pages/user/order/course_detail?id='.$order['id']
//            );
//            print_r($res);
//        }
//    }


    //座位混乱，重新按照订单状态更新一遍
//    public function seat_aync()
//    {
//        $orderModel = new OrderModel();
//        $orderlist = $orderModel->order('id desc')->select();
//        $seatModel = new CourseOrderSeatModel();
//        foreach ($orderlist as $order) {
//            $seatInfo = $seatModel->where(['order_id'=>$order['id']])->find();
//            if($order['status'] == 0){
//                if($seatInfo){
//                    $seatModel->where(['order_id'=>$order['id']])->update(['status'=>0]);
//                }
//            }
//            if($order['status'] > 0){
//                if($seatInfo){
//                    $seatModel->where(['order_id'=>$order['id']])->update(['status'=>1]);
//                }
//            }
//            if($order['status'] < 0){
//                if($seatInfo){
//                    $seatModel->where(['order_id'=>$order['id']])->update(['status'=>2]);
//                }
//            }
//
//        }
//    }

    //清楚某个用户的订单记录
    public function empty_user_data()
    {
//        $user_id = 1;
//        $xykeep_user_course_log_count = 0;
//        $xykeep_user_course_count = 0;
//
//        $user_course_list = Db::name('xykeep_user_course')->where(['user_id'=>$user_id])->select();
//        foreach ($user_course_list as $user_course) {
//            Db::name('xykeep_user_course_log')->where(['user_course_id'=>$user_course['id']])->delete();
//            $xykeep_user_course_log_count ++;
//            Db::name('xykeep_user_course')->where(['id'=>$user_course['id']])->delete();
//            $xykeep_user_course_count ++;
//        }
//
//        $xykeep_course_order_count = 0;
//        $xykeep_course_order = Db::name('xykeep_course_order')->where(['user_id'=>$user_id])->select();
//        foreach ($xykeep_course_order as $val) {
//            Db::name('xykeep_course_order')->where(['id'=>$val['id']])->delete();
//            $xykeep_course_order_count ++;
//        }
//
//        $xykeep_course_order_seat_count = 0;
//        $xykeep_course_order_seat = Db::name('xykeep_course_order_seat')->where(['user_id'=>$user_id])->select();
//        foreach ($xykeep_course_order_seat as $val) {
//            Db::name('xykeep_course_order_seat')->where(['id'=>$val['id']])->delete();
//            $xykeep_course_order_seat_count ++;
//        }
//
//        $xykeep_vip_order_count = 0;
//        $xykeep_vip_order = Db::name('xykeep_vip_order')->where(['user_id'=>$user_id])->select();
//        foreach ($xykeep_vip_order as $val) {
//            Db::name('xykeep_vip_order')->where(['id'=>$val['id']])->delete();
//            $xykeep_vip_order_count ++;
//        }
//
//        $xykeep_user_vip_count = 0;
//        $xykeep_user_vip_log_count = 0;
//        $xykeep_user_vip = Db::name('xykeep_user_vip')->where(['user_id'=>$user_id])->select();
//        foreach ($xykeep_user_vip as $val) {
//            Db::name('xykeep_user_vip')->where(['id'=>$val['id']])->delete();
//            $xykeep_user_vip_log = Db::name('xykeep_user_vip_log')->where(['user_vip_id'=>$val['id']])->select();
//            foreach ($xykeep_user_vip_log as $v) {
//                Db::name('xykeep_user_vip_log')->where(['id'=>$v['id']])->delete();
//                $xykeep_user_vip_log_count ++;
//            }
//            $xykeep_user_vip_count ++;
//        }
//
//
//
//
//        echo '删除课程订单'.$xykeep_course_order_count.'条';
//        echo '<br/>';
//        echo '删除课程订单座位'.$xykeep_course_order_seat_count.'条';
//        echo '<br/>';
//        echo '删除用户课程'.$xykeep_user_course_count.'条';
//        echo '<br/>';
//        echo '删除用户课程日志'.$xykeep_user_course_log_count.'条';
//        echo '<br/>';
//
//
//        echo '删除用户课包订单'.$xykeep_vip_order_count.'条';
//        echo '<br/>';
//        echo '删除用户课包'.$xykeep_user_vip_count.'条';
//        echo '<br/>';
//        echo '删除用户课包日志'.$xykeep_user_vip_log_count.'条';
//        echo '<br/>';

    }

    //检查用户分销父id是否同步
//    public function check_parent_id(){
//        $user_list = Db::name('user')->select();
//        foreach ($user_list as $item) {
//            if($item['xykeep_parent_user_id'] !== 0){
//                $distribution = Db::name('xykeep_distribution')->where(['user_id'=>$item['id']])->find();
//                if($distribution['pid']!==$item['xykeep_parent_user_id']){
//                    echo $item['id'].',';
//                }
//            }
//        }
//    }
}
